package com.example.shishaolong.warehousemanager;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import com.example.shishaolong.warehousemanager.common.DateUtil;
import com.example.shishaolong.warehousemanager.dao.GoodsDao;
import com.example.shishaolong.warehousemanager.entity.GoodsEntity;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

/**
 * 货物数据访问层测试
 *
 * @author 时少龙
 */
@RunWith(AndroidJUnit4.class)
public class GoodsDaoTest {

    private Context context;

    @Before
    public void init() {
        context = InstrumentationRegistry.getTargetContext();
    }

    @Test
    public void addGoods() {
        System.out.println("测试添加物品");
        GoodsDao goodsDao = new GoodsDao(context);
        for (int i = 0; i < 10; i++) {
            GoodsEntity goodsEntity = new GoodsEntity();
            goodsEntity.setName("安卓作业本"+i);
            goodsEntity.setReceivePerson("龙龙");
            goodsEntity.setDescribe("这是课程设计的论文");
            goodsEntity.setBuyerName("时少龙"+i);
            goodsEntity.setStorageDate(DateUtil.getCurrentDateStr());
            goodsEntity.setOutDate(DateUtil.getCurrentDateStr());
            goodsEntity.setModifyDate(DateUtil.getCurrentDateStr());
            goodsDao.add(goodsEntity);
        }
    }

    @Test
    public void findAllGoods() {
        System.out.println("测试查询所有的数据");
        GoodsDao goodsDao = new GoodsDao(context);
        List<GoodsEntity> goodsEntityList = goodsDao.findAll();
        for (GoodsEntity goodsEntity : goodsEntityList) {
            System.out.println(goodsEntity);
        }
    }

    @Test
    public void deleteAll() {
        System.out.println("测试删除全部：");
        GoodsDao goodsDao = new GoodsDao(context);
        goodsDao.deleteAll();
    }

    @Test
    public void updateGoods() {
        System.out.println("测试修改");
        GoodsDao goodsDao = new GoodsDao(context);
        GoodsEntity goodsEntity = goodsDao.findById(16);
        System.out.println(goodsEntity);
        goodsEntity.setName("计算机网络书");
//        goodsEntity.setAllNum(78);
        goodsEntity.setBuyerName("小红");
        goodsEntity.setReceivePerson("龙龙小哥");
        goodsDao.update(goodsEntity);
    }

    @Test
    public void deleteById() {
        System.out.println("测试删除单个物品");
        GoodsDao goodsDao = new GoodsDao(context);
        goodsDao.delete(15);

    }
}
